package cn.yuanqiao.web.controller.archive.shuzihua;

import cn.yuanqiao.archive.appManager.domain.TenantYqFolder;
import cn.yuanqiao.archive.detection.domain.DetectionPackage;
import cn.yuanqiao.archive.detection.service.IDetectionObjectService;
import cn.yuanqiao.archive.shuzihua.service.DangAnJieShouService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zjj
 * @date 2023/7/18
 */
@RestController
@RequestMapping("/archive/szh")
public class DangAnJieShouController extends BaseController {

    @Autowired
    private DangAnJieShouService dangAnJieShouService;
    @Autowired
    private IDetectionObjectService detectionObjectService;

    /**
     * 添加项目
     * @param object
     * @return
     */
    @Log(title = "添加项目", businessType = BusinessType.INSERT)
    @PostMapping("/addItemDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:addItem')")
    public AjaxResult addItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.addItem(object);
        return AjaxResult.success();
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PostMapping("/addFolderDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:addFolderDa')")
    public AjaxResult addFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        TenantYqFolder folder = dangAnJieShouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PostMapping("/addFolderDa1")
    @PreAuthorize("@ss.hasPermi('archive:szh:addFolderDa1')")
    public AjaxResult addFolder1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        TenantYqFolder folder = dangAnJieShouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    /**
     * 添加件
     * @param object
     * @return
     */
    @Log(title = "添加件", businessType = BusinessType.INSERT)
    @PostMapping("/addYqdaDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:addYqdaDa')")
    public AjaxResult addYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.addYqda(object);
        return AjaxResult.success();
    }

    /**
     * 修改项目
     * @param object
     * @return
     */
    @Log(title = "修改项目", businessType = BusinessType.UPDATE)
    @PostMapping("/updateItemDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:updateItemDa')")
    public AjaxResult updateItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.updateItem(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PostMapping("/updateFolderDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:updateFolderDa')")
    public AjaxResult updateFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PostMapping("/updateFolderDa1")
    @PreAuthorize("@ss.hasPermi('archive:szh:updateFolderDa1')")
    public AjaxResult updateFolder1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组件
     * @param object
     * @return
     */
    @Log(title = "修改组件", businessType = BusinessType.UPDATE)
    @PostMapping("/updateYqdaDa")
    @PreAuthorize("@ss.hasPermi('archive:szh:updateYqdaDa')")
    public AjaxResult updateYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        dangAnJieShouService.updateYqda(object);
        return AjaxResult.success();
    }

    @Log(title = "接收按钮", businessType = BusinessType.UPDATE)
    @PostMapping("/jieshouDa")
    //@PreAuthorize("@ss.hasPermi('archive:szh:jieshouDa')")
    public AjaxResult updateYqda(@RequestParam("categoryId")Long categoryId,@RequestParam("ids")Long[] ids){

        return AjaxResult.success(dangAnJieShouService.jieshou(categoryId,ids));
    }

    @Log(title = "数字化-接收按钮", businessType = BusinessType.UPDATE)
    @PostMapping("/jieshouSzhDa")
    //@RequiresPermissions("archive:szh:jieshouDa")
    public AjaxResult updateYqdaSzh(@RequestParam("categoryId")Long categoryId,@RequestParam("ids")Long[] ids){
        Map map=dangAnJieShouService.jieshouszh(categoryId,ids);
        return AjaxResult.success(map);
    }

    @Log(title = "接收按钮", businessType = BusinessType.UPDATE)
    @PostMapping("/dgdJieshou")
    //@PreAuthorize("@ss.hasPermi('archive:szh:jieshouDa')")
    public AjaxResult dgdJieshou(@RequestBody DetectionPackage packages){

//        Boolean result = true; //检查结果
//        if(result){
//            dangAnJieShouService.dgdJieshou(categoryId,ids);
//        }
        Map map = detectionObjectService.daIdsDetection(packages);

        return AjaxResult.success(map);
    }


}
